var mongoose = require('mongoose');
let conn = mongoose.createConnection('mongodb://localhost/test');

const schema = mongoose.Schema({
    subjectId: {type: Number, required: true},
    question_count: {type: Number, required: true},
    change_logs: {type: Array},
    create_time: {type: Date, required: true},
    update_time: {type: Date}
}, {versionKey: false, collection: "cutTaskStatic"});

let cutTaskModel = conn.model('cutTaskStatic', schema);

let task = {
    subjectId: '123434',
    question_count: 12,
    change_logs: [
        {
            name: '张三',
            age: 12
        }
    ],
    create_time: new Date()
}

// cutTaskModel.create(task,(err,res)=>{
//     if (err) console.log(err);
//     console.log(res);
// })

async function test() {
    return new Promise((resolve, reject) => {
        cutTaskModel.find().where({subjectId: '123434'}).select({}).exec((err, res) => {
            if (err) return reject(err);
            return resolve(res);
        });
    })
}

// test().then((res) => {
//     if (res) console.log(res);
//
// }).catch(e => {
//     if (e) console.log(`have error :${e}`);
// })

async function  a(){
    let a = await test().then((res) => {return res});
    console.log(a)
}

a()
//
// cutTaskModel.update({subjectId:'123434'},{'$push':{'change_logs':{name:'lisi',age:15}},update_time: new Date()},(err,res)=>{
//     if (err) console.log(err);
//     console.log(res)
// })
